package com.retail.xiaocui.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.retail.system.common.domain.SysUser;
import com.retail.xiaocui.common.domain.req.PurchaseReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.xiaocui.common.domain.Purchase;
import com.retail.xiaocui.server.service.PurchaseService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 采购申请单Controller
 *
 * @author retail
 * @date 2024-03-05
 */
@RestController
@RequestMapping("/purchase")
public class PurchaseController extends BaseController
{
    @Autowired
    private PurchaseService purchaseService;




    /**
     * 查询采购申请单列表
     */
    @RequiresPermissions("xiaocui:purchase:list")
    @GetMapping("/list")
    public TableDataInfo list(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchaseList(purchase);
        return getDataTable(list);
    }

    /**
     * 导出采购申请单列表
     */
    @RequiresPermissions("xiaocui:purchase:export")
    @Log(title = "采购申请单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Purchase purchase)
    {
        List<Purchase> list = purchaseService.selectPurchaseList(purchase);
        ExcelUtil<Purchase> util = new ExcelUtil<Purchase>(Purchase.class);
        util.exportExcel(response, list, "采购申请单数据");
    }



    /**
     * 获取采购申请单详细信息
     */
    @RequiresPermissions("xiaocui:purchase:query")
    @GetMapping(value = "/{procurementId}")
    public Result getInfo(@PathVariable("procurementId") Integer procurementId)
    {
        return success(purchaseService.selectPurchaseByProcurementId(procurementId));
    }

    /**
     * 新增采购申请单
     */
    @RequiresPermissions("xiaocui:purchase:add")
    @Log(title = "采购申请单", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Purchase purchase)
    {
        return toAjax(purchaseService.insertPurchase(purchase));
    }

    /**
     * 修改采购申请单
     */
    @RequiresPermissions("xiaocui:purchase:edit")
    @Log(title = "采购申请单", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Purchase purchase)
    {
        return toAjax(purchaseService.updatePurchase(purchase));
    }

    /**
     * 删除采购申请单
     */
    @RequiresPermissions("xiaocui:purchase:remove")
    @Log(title = "采购申请单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{procurementIds}")
    public Result remove(@PathVariable Integer[] procurementIds)
    {
        return toAjax(purchaseService.deletePurchaseByProcurementIds(procurementIds));
    }

    /**
     * 查询所有用户
     * @return
     */
    @PostMapping("/userList")
    public Result userList(){
        return purchaseService.userList();
    }


    /**
     * 分配采购人员
     * @param
     * @return
     */
    @PostMapping("/userUpdatePurchase")
    public Result userUpdatePurchase(@RequestBody PurchaseReq purchaseReq){
        return purchaseService.userUpdatePurchase(purchaseReq);
    }

}
